﻿using System;
using System.Linq;
using System.Windows.Forms;
using whu2020302051098.DAL;
using whu2020302051098.Model;

namespace whu2020302051098 {

    public partial class RegisterForm : Form {
        public RegisterForm() {
            InitializeComponent();
            this.schoolTxt.Items.Add("信息学部");
            this.schoolTxt.Items.Add("文理学部");
            this.schoolTxt.Items.Add("工学部");
            this.schoolTxt.Items.Add("医学部");
            this.schoolTxt.SelectedItem = 0;
        }

        private void confirmBtn_Click(object sender, EventArgs e)
        {
            var studentList = SqlDao.SelectStudentList();
            var schoolList = SqlDao.SelectSchoolList();

            String stuNo = (Int32.Parse(studentList.Last().No)+1).ToString();
            String schNo = (Int32.Parse(schoolList.Last().No)+1).ToString();

            SqlDao.InsertSchool(new School(schNo, schoolTxt.SelectedItem.ToString(), locationTxt.Text));
            SqlDao.InsertStudent(new Student(stuNo,nameTxt.Text, schNo, sexTxt.Text, dateTimePicker.Text,classTxt.Text));
            
        }

        private void cancelBtn_Click(object sender, EventArgs e) {
            Close();
        }
    }
}
